<template>
  <div class="flex items-center">
    <el-icon v-if="modelValue" class="mr-2" :size="20">
      <component :is="modelValue" />
    </el-icon>
    <el-select
      :modelValue="modelValue"
      @change="handleChange"
      placeholder="请选择"
      filterable
    >
      <el-option v-for="item in icons" :key="item" :label="item" :value="item">
        <div class="flex items-center justify-between">
          <el-icon>
            <component :is="item" />
          </el-icon>
          <span>{{ item }}</span>
        </div>
      </el-option>
    </el-select>
  </div>
</template>

<script setup>
  import { ref } from 'vue'
  import * as iconList from '@element-plus/icons-vue'

  const props = defineProps({
    modelValue: String,
  })
  const emit = defineEmits(['update:modelValue'])

  const icons = ref(Object.keys(iconList))

  function handleChange(e) {
    emit('update:modelValue', e)
  }
</script>

<style scoped></style>
